package com.mes.task.domain;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.Formula;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.context.annotation.Lazy;

import com.mes.common.domain.BasicModel;

/**
 * <p>
 * author lcs
 * data 2017-03-26
 * </p>
 * 
 */
@Entity()
//@org.hibernate.annotations.Entity(dynamicInsert=true,dynamicUpdate=true)
@Table(name = "T_DEMANDTASKLINKS")
@BatchSize(size=20)
@Lazy(value=true)
//@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class DemandTaskLink extends BasicModel {

	public final static int LOCKLEVEL_LOCKED = 1; // 已锁定
	public final static int LOCKLEVEL_UNLOCKED = 0; // 未锁定
	public final static int ISINEFFECT_IS = 1; // 生效
	public final static int ISINEFFECT_ISNOT = 0; // 未生效
	
	@Id
	@GenericGenerator(name = "uniqueId", strategy = "assigned")
	@Column(name="UNIQUE_ID",length=50)
	private String uniqueId;
	
	public String getUniqueId() {
		return uniqueId;
	}

	public void setUniqueId(String uniqueId) {
		this.uniqueId = uniqueId;
	}

	@Override
	public String getUuid() {
		return uniqueId;
	}

	@Override
	public void setUuid(String uuid) {
		this.uniqueId = uuid;
	}

	@Column(name="SUCCUID")
	protected String demandUid;
	/**
	 * ���Ӷ���ӳ��--successor
	 */
	//many-to-one
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn(name="SUCCUID",insertable=false,updatable=false)
	protected Demand demand;

	@Column(name="PREDUID")
	protected String partTaskUid;
	/**
	 * ���Ӷ���ӳ��--precessor
	 */
	//many-to-one
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn(name="PREDUID",insertable=false,updatable=false)
	protected PartTask partTask;

	@Column(name="LINKQTY",precision=25,scale=6)
	protected Float linkQty;

	@Formula("(select tt1.planqty-(select nvl(sum(tl.linkqty), 0) from t_demandtasklinks tl where tl.preduid = PREDUID and tl.isIneffect=1 and tl.succuid != SUCCUID) from t_tasks tt1 where tt1.taskuid = PREDUID)")
	protected Float availableQty;

	@Column(name="ISINEFFECT")
	protected Integer isInEffect;

	@Column(name="DEPENDTYPE")
	protected String dependType;

	@Column(name="LOCKLEVEL")
	protected Integer lockLevel;

	@Column(name="LOCKEXPIREDATE",length=7)
	protected Date lockExpireDate;

	/**
	 * �յĹ��캯��
	 */
	public DemandTaskLink() {

	}

	public String getDemandUid() {
		return demandUid;
	}

	public void setDemandUid(String demandUid) {
		this.demandUid = demandUid;
	}

	public Demand getDemand() {
		return demand;
	}

	public void setDemand(Demand demand) {
		this.demand = demand;
	}

	public String getPartTaskUid() {
		return partTaskUid;
	}

	public void setPartTaskUid(String partTaskUid) {
		this.partTaskUid = partTaskUid;
	}

	public PartTask getPartTask() {
		return partTask;
	}

	public void setPartTask(PartTask partTask) {
		this.partTask = partTask;
	}

	public Float getLinkQty() {
		return linkQty;
	}

	public void setLinkQty(Float linkQty) {
		this.linkQty = linkQty;
	}

	public Integer getIsInEffect() {
		return isInEffect;
	}

	public void setIsInEffect(Integer isInEffect) {
		this.isInEffect = isInEffect;
	}

	public Integer getLockLevel() {
		return lockLevel;
	}

	public void setLockLevel(Integer lockLevel) {
		this.lockLevel = lockLevel;
	}

	public Date getLockExpireDate() {
		return lockExpireDate;
	}

	public void setLockExpireDate(Date lockExpireDate) {
		this.lockExpireDate = lockExpireDate;
	}

	public String getDependType() {
		return dependType;
	}

	public void setDependType(String dependType) {
		this.dependType = dependType;
	}

	public Float getAvailableQty() {
		return availableQty;
	}

	public void setAvailableQty(Float availableQty) {
		this.availableQty = availableQty;
	}

}